﻿
namespace UserInterface.Gateways
{
    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Data.Services.Client;
    using System.Linq;
    using UserInterface.AUSRISservice;

    public class CourseSectionGateway : ICourseSectionGateway
    {
        private AUSRISEntities context;

        public CourseSectionGateway()
        {
            Uri serviceUri = new Uri(ConfigurationManager.AppSettings["ServiceUri"]);
            this.context = new AUSRISEntities(serviceUri);
            this.context.MergeOption = MergeOption.AppendOnly;
        }

        public au_CourseSection GetCourseSection(int courseSectionId)
        {
            var courseSection = from c in this.context.au_CourseSection
                                where c.Id == courseSectionId                                
                                select c;

            courseSection.

            return courseSection;
        }

        public IList<au_CourseSection> GetCourseSections(au_Program program)
        {
            int programId = program.Id;
            string programEntId = program.EnterpriseId;

            IEnumerable<au_CourseSection> courseSections = this.context.Execute<au_CourseSection>(
                new Uri(this.context.BaseUri.ToString() +
                    "/au_Program(" + programId + ")"));

            List<au_CourseSection> courseSectionSet = new List<au_CourseSection>();
            foreach(au_CourseSection c in courseSections)
            {
                courseSectionSet.Add(c);
            }

            return courseSectionSet;
        }

        public IList<au_CourseSection> GetTermCourseSections(au_Term term)
        {
            int termId = term.Id;

            IEnumerable<au_CourseSection> courseSections = this.context.Execute<au_CourseSection>(
                new Uri(this.context.BaseUri.ToString() +
                    "/au_Term(" + termId + ")"));

            List<au_CourseSection> courseSectionSet = new List<au_CourseSection>();
            foreach(au_CourseSection c in courseSections)
            {
                courseSectionSet.Add(c);
            }

            return courseSectionSet;
        }

        public void DeleteCourseSection(au_CourseSection courseSection)
        {
            throw new NotImplementedException();
        }

        public void UpdateCourseSection(au_CourseSection courseSection)
        {
            throw new NotImplementedException();
        }

        public void AddCourseSection(au_CourseSection courseSection)
        {
            throw new NotImplementedException();
        }
    }
}
